#ifndef __SPDF_EXT_H__
#define __SPDF_EXT_H__

#include "spdf_opt.h"
#include "rtctime.h"
#include "mytype.h"

#ifdef __cplusplus
extern "C"
{
#endif

#define SPDF_FORM_ALAIN_LEFT 0
#define SPDF_FORM_ALAIN_MID 1

	typedef struct
	{
		ii16 x0, y0;
		SPDF_Page page;

		struct
		{
			ii16 num;
			ii16 *size_list;
			ii16 fixd_size;
		} col;

		struct
		{
			ii16 num;
			ii16 size;
		} row;

		struct
		{
			ii16 y_offset, x_offset, font_size;
			ii16 x, y;
			ii16 col, row;
			uu8 alain;	   
			uu8 hex_force; 
		} txt;

		struct
		{
			ii16 ext_wide;			 
			ii16 inn_wide;			 
			uu8 ext_r, ext_g, ext_b; 
			uu8 inn_r, inn_g, inn_b; 
			uu8 ext_dash_len1;		 
			uu8 ext_dash_len0;		 
			uu8 inn_dash_len1;		 
			uu8 inn_dash_len0;		 
		} frame;
	} spdf_form_type;

	typedef struct
	{
		uu8 r, g, b;
	} spdf_color_type;

	void spdf_form_page_mount(spdf_form_type *form, SPDF_Page page);

	void spdf_form_row_set(spdf_form_type *form, ii16 num, ii16 size);

	void spdf_form_col_set(spdf_form_type *form, ii16 num, ii16 *size, ii16 fixed_size);

	void spdf_form_org(spdf_form_type *form, ii16 x, ii16 y);

	void spdf_form_frame_ext_set(spdf_form_type *form, ii16 wide, uu8 r, uu8 g, uu8 b);
	void spdf_form_frame_inn_set(spdf_form_type *form, ii16 wide, uu8 r, uu8 g, uu8 b);

	void spdf_form_draw(spdf_form_type *form);

	void spdf_form_line_sp(spdf_form_type *form,
						   ii16 row, ii16 col,
						   ii16 x0, ii16 y0,
						   ii16 x1, ii16 y1);

	void spdf_form_text_start(spdf_form_type *form);

	void spdf_form_text_end(spdf_form_type *form);

	void spdf_form_text_offset(spdf_form_type *form, ii16 x, ii16 y);

	void spdf_form_text_font(spdf_form_type *form, const char *font_name, ii16 size);

	void spdf_form_text_alain(spdf_form_type *form, uu8 alain);

	void spdf_form_text(spdf_form_type *form, ii16 row, ii16 col, const char *text);
	void spdf_form_text_ext(spdf_form_type *form, ii16 row, ii16 col, const char *text, spdf_color_type *backcolor, spdf_color_type *forecolor);

	void spdf_form_text_sp(spdf_form_type *form,
						   ii16 row, ii16 col,
						   ii16 x_offset, ii16 y_offset,
						   const char *text);

	void spdf_form_text_next_row(spdf_form_type *form);

	void spdf_form_text_next_col(spdf_form_type *form);

	void spdf_form_text_auto(spdf_form_type *form, const char *text);
	void spdf_form_text_auto_ext(spdf_form_type *form, const char *text, spdf_color_type *backcolor, spdf_color_type *forecolor);

	typedef struct
	{
		uu8 wide;	 
		uu8 r, g, b; 
	} spdf_chart_base_line_type;

	typedef struct
	{
		spdf_chart_base_line_type attr; 
		ii16 site;						
		ii8 len1;						
		ii8 len0;						
		const char *name;				
	} spdf_chart_hl_type;

	typedef struct
	{
		ii16 site;		   
		uu8 wide;		   
		ii8 lmode;		   
		ii8 len1;		   
		ii8 len0;		   
		const char *xname; 
		const char *yname; 
	} spdf_chart_vl_type;

	typedef struct
	{
		ii16 x_pos;
		ii16 val;
	} spdf_chart_point_type;

	typedef struct
	{
		spdf_chart_base_line_type attr; 
		uu16 point_pos_offset;			
		uu16 point_amount;				
		const void *point_val_list;		
		ii16 point_val_offset;			
		ii16 point_val_coef;			
		ii16 axis_y_offset;				
		ii16 axis_x_inc;				
		uu8 point_mode;					
										
		uu8 v_l_amount;					
		const spdf_chart_vl_type *v_l;	
	} spdf_chart_line_type;

	typedef struct
	{
		uu8 r, g, b;	
		uu8 ipn;		
		uu8 val_attr;	
		char *unit;		
		ii32 val_start; 
		ii32 val_inc;	
	} spdf_chart_ytxt_type;

	typedef struct
	{
		ii16 x0, y0;		
		ii16 width, height; 
		SPDF_Page page;		

		struct
		{
			spdf_chart_base_line_type l_axis;	
			spdf_chart_base_line_type l_grid_m; 
			spdf_chart_base_line_type l_grid_s; 
			ii16 grid_x_m_wide;					
			ii16 grid_y_m_wide;					
			ii8 grid_x_s_num;					
			ii8 grid_y_s_num;					
			ii8 arrows_offset;					
			ii8 arrows_size;					
			uu8 mode;							
			ii8 scale_s_size;					
			ii8 scale_m_size;					
			
			uu8 hl_amount;				  
			const spdf_chart_hl_type *hl; 
		} frame;

		struct
		{
			uu8 enable; 

			ii16 site_offset_y;
			ii16 site_offset_x;

			uu8 x_mode;			 
			uu8 x_r, x_g, x_b;	 
			uu8 x_val_ipn;		 
			ii16 x_val_inc;		 
			ii32 x_val_start;	 
			sig_time_type x_rtc; 

			const spdf_chart_ytxt_type *ytxt; 
			uu8 y_txt_num;					  

			ii8 font_size;		   
			const char *font_name; 
			
			ii16 x, y;
		} txt;

		struct
		{
			uu8 axis_draw; 
		} st;

		uu8 dir;							   
		uu8 line_num;						   
		const spdf_chart_line_type *line_list; 

	} spdf_chart_type;

	void spdf_chart_mount(spdf_chart_type *chart, SPDF_Page page);

	void spdf_chart_show(spdf_chart_type *chart);

	void spdf_chart_default(spdf_chart_type *chart);

	void spdf_chart_axis(spdf_chart_type *chart, uu8 wide, uu8 r, uu8 g, uu8 b);
	void spdf_chart_grid_m(spdf_chart_type *chart, uu8 wide, uu8 r, uu8 g, uu8 b);
	void spdf_chart_grid_s(spdf_chart_type *chart, uu8 wide, uu8 r, uu8 g, uu8 b);

	void spdf_chart_txt_show(spdf_chart_type *chart);

	void spdf_chart_line_add(spdf_chart_type *chart, const spdf_chart_line_type *line);

#ifdef __cplusplus
}
#endif

#endif 
